<template>
	<view class="content">
		<u-empty :text="text" mode="list" style="height: 100vh;" v-if="getInfoType === 'fail'"></u-empty>
		<u-cell-group v-else-if="getInfoType === 'success'">
			<u-cell title="设备名称" :value="info.name"></u-cell>
			<u-cell title="生产厂家" :value="info.productionFactory"></u-cell>
			<u-cell title="设备编码" :value="info.code"></u-cell>
			<u-cell title="设备型号" :value="info.modelNo"></u-cell>
			<u-cell title="生产日期" :value="info.productionDate"></u-cell>
			<u-cell title="质保期" :value="info.maintenanceDeadline"></u-cell>
		</u-cell-group>
	</view>
</template>

<script>
	import {
		getUrlParam
	} from '@/utils/index.js'
	export default {
		data() {
			return {
				// 空状态文本提示
				text: '',
				// 获取详情状态
				getInfoType: '',
				// 数据详情
				info: {
					name: '',
					productionFactory: '',
					code: '',
					modelNo: '',
					productionDate: '',
					maintenanceDeadline: ''
				},
			};
		},
		onLoad() {
			this.init()
		},
		methods: {
			// 初始化
			init() {
				const code = getUrlParam('code')
				this.$http('/elevator/eleDevice/select', 'post', {
						code,
						osType: 1
					}, false)
					.then((res) => {
						this.info = res.data
						if(this.info) {
							const field = 'productionDate'
							this.info[field] = this.info[field].split(' ')[0]
						}
						else this.text = '该设备信息待完善'
						this.getInfoType = this.info ? 'success' : 'fail'
					}).catch(err => {
						this.text = err.msg
						this.getInfoType = 'fail'
					})
			},
			// 获取code
			// getParams(URL) {
			// 	const params = {};
			// 	if (URL.split('?')[1]) {
			// 		const arr = URL.split('?')[1].split('&');
			// 		for (let i = 0; i < arr.length; i++) {
			// 			const arrNew = arr[i].split('=');
			// 			params[arrNew[0]] = arrNew[1];
			// 		}
			// 	}
			// 	return params
			// }
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background: #fff;
	}

	.content {

		// padding: 0 32rpx;
		.button {
			margin-top: 80rpx;
		}
	}
</style>